<template>
  <div class="main-container">
    <div class="register-container">
      <h2 class="title">商户注册</h2>
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" class="register-form">
        <el-form-item prop="shangjiazhanghao">
          <el-input v-model="ruleForm.shangjiazhanghao" placeholder="请输入商户账号"></el-input>
        </el-form-item>
        <el-form-item prop="mima">
          <el-input type="password" v-model="ruleForm.mima" placeholder="请输入密码"></el-input>
        </el-form-item>
        <el-form-item prop="shangjiamingcheng">
          <el-input v-model="ruleForm.shangjiamingcheng" placeholder="请输入商户名称"></el-input>
        </el-form-item>
        <el-form-item prop="lianxidianhua">
          <el-input v-model="ruleForm.lianxidianhua" placeholder="请输入联系电话"></el-input>
        </el-form-item>
        <el-form-item prop="youxiang">
          <el-input v-model="ruleForm.youxiang" placeholder="请输入邮箱"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="register" class="register-btn">注册</el-button>
        </el-form-item>
        <div class="login-link">
          <router-link to="/shangjia/login">已有账号？立即登录</router-link>
        </div>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      ruleForm: {
        shangjiazhanghao: '',
        mima: '',
        shangjiamingcheng: '',
        lianxidianhua: '',
        youxiang: ''
      },
      rules: {
        shangjiazhanghao: [
          { required: true, message: '请输入商户账号', trigger: 'blur' }
        ],
        mima: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ],
        shangjiamingcheng: [
          { required: true, message: '请输入商户名称', trigger: 'blur' }
        ],
        lianxidianhua: [
          { required: true, message: '请输入联系电话', trigger: 'blur' }
        ],
        youxiang: [
          { required: true, message: '请输入邮箱', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    register() {
      this.$refs.ruleForm.validate(valid => {
        if (valid) {
          this.$http.post('/shangjia/register', this.ruleForm).then(({data}) => {
            if (data && data.code === 0) {
              this.$message.success('注册成功')
              this.$router.push('/shangjia/login')
            } else {
              this.$message.error(data.msg)
            }
          })
        }
      })
    }
  }
}
</script>

<style scoped>
.main-container {
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #f0f2f5;
}
.register-container {
  width: 400px;
  padding: 40px;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
}
.title {
  text-align: center;
  margin-bottom: 30px;
}
.register-btn {
  width: 100%;
}
.login-link {
  text-align: center;
  margin-top: 20px;
}
</style>